package leetcode.code1417;

import leetcode.IDebug;

public class Solution implements IDebug {

	public String reformat(String s) {
		char[] cs = s.toCharArray();
		int cnt1 = 0, cnt2 = 0;
		for (char c : cs) {
			if (c >= '0' && c <= '9') {
				cnt1++;
			} else {
				cnt2++;
			}
		}
		if (Math.abs(cnt1 - cnt2) > 1) {
			return "";
		}
		boolean num = false;
		if (cnt1 > cnt2) {
			num = true;
		}
		char[] ans = new char[cs.length];
		int p1 = 0, p2 = 1;
		for (char c : cs) {
			if (c >= '0' && c <= '9') {
				if (num) {
					ans[p1] = c;
					p1 += 2;
				} else {
					ans[p2] = c;
					p2 += 2;
				}
			} else {
				if (!num) {
					ans[p1] = c;
					p1 += 2;
				} else {
					ans[p2] = c;
					p2 += 2;
				}
			}
		}
		return new String(ans);
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
